%% Dynamic Factor Model for Mixed Frequency Data
%  With Time-Varying Intercepts and Stochastic Volatility

clear
clc

addpath('functions');
addpath('data');
 
seed = RandStream('mt19937ar','Seed',1);
RandStream.setGlobalStream(seed);

%% Settings

% Data Adjustments

settings.panelsize = 28;

settings.remove_means = 1;
settings.standardise = 0;                               % Standardise all Variables Prior to estimation (optional)
settings.remove_outliers = 1;                           % Remove outliers following Stock and Watson (reccommended)

% Model Specification

settings.WhereQuarterly = [1:4];
settings.soft6 = [];

settings.constant = 0;                                  % Add constant in VAR

settings.nf = 1;                                        % Number of latent factors

settings.p = 2;                                         % Maximum lag order of factor VAR
settings.s = 0;
settings.q = 2;                                         % Order of serial correlation in idiosyncratic components. Max = 5;

settings.SV_factors = 1;                                % Add Stochastic Volatility to the common factors (0 = no; 1 = yes);
settings.SV_idiosyncratic = 1;
                         
                              
% Gibss Sampler Setting

settings.nreps = 7000;       % Number of Gibbs Sampler Draws
settings.nburn = 2000;       % Discard the first nburn draws as Burn-in Draws

settings.show_plots = 0;
settings.plot_each = 100;

%% Bayesian Priors

settings.var_priors = 0;     % 0 = Noninformative; 1 = Independent N-IW;
settings.lambda_priors = 0;   % 0 = Noninformative; 1 = shrink towards zero
settings.rho_priors = 0;     % 0 = Noninformative; 1 = shrink towards zero

settings.prior_SV = 1E-4;
settings.prior_SV_sm = 1E-4;


%% Run DFM for Baseline Case

settings.trend = 1;
settings.schemenumber = 51;
settings.prior_trend = 0.001;

load('ADP_baseline.mat');
[results] = DFM_function3_Simple(settings,yraw,dates,datenum(now));

% Save results
save('output\results_Figure2','results','settings','yraw')
